package stsj.meddroid.screen;

import stsj.meddroid.Resources;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.Camera;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;

public class LoadingScreen implements Screen , InputProcessor{

	private Screen lastScreen;
	private int round;

	private Camera camera;
	private SpriteBatch batch;

	private long startTime;
	private long currentTime;
	private boolean initialized;

	public LoadingScreen(Screen lastScreen, int round) {
		this.lastScreen = lastScreen;
		this.round = round;
		initialized = false;
		camera = Resources.camera;
//		camera.position.set(240, 160, 0);
	}

	@Override
	public void dispose() {

	}

	@Override
	public void hide() {

		dispose();

	}

	@Override
	public void pause() {

	}

	@Override
	public void render(float arg0) {

		Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
		currentTime = System.currentTimeMillis();
		batch.begin();
//		batch.draw(Resources.backgroundRegion, 0, 0);
//		batch.draw(Resources.battleDialog, 240, 160);
		batch.draw(Resources.kataLoadings[0], 480 - Resources.kataLoadings[0].getRegionWidth(), 0);
		batch.end();
		camera.update();
		batch.setProjectionMatrix(camera.combined);

		if (!initialized) {

		
			initialized = true;
		}

		if (currentTime - startTime > 700) {
			if (lastScreen instanceof RoundSelectScreen) {
				((RoundSelectScreen) lastScreen).startBattle(round);
			} else if (lastScreen instanceof StoryScreen) {
				((StoryScreen) lastScreen).startBattle(round);
			}
			
		}
	}

	@Override
	public void resize(int arg0, int arg1) {

	}

	@Override
	public void resume() {

	}

	@Override
	public void show() {

		camera.position.set(Resources.VP_WIDTH/2, Resources.VP_HEIGHT/2, 0);
		
		System.gc();
		Gdx.input.setCatchBackKey(false);
		batch = Resources.batch;
		batch.setProjectionMatrix(camera.combined);
		startTime = System.currentTimeMillis();
		Gdx.input.setInputProcessor(this);

	}

	@Override
	public boolean keyDown(int arg0) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean keyTyped(char arg0) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean keyUp(int arg0) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean scrolled(int arg0) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean touchDown(int arg0, int arg1, int arg2, int arg3) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean touchDragged(int arg0, int arg1, int arg2) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean touchMoved(int arg0, int arg1) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean touchUp(int arg0, int arg1, int arg2, int arg3) {
		// TODO Auto-generated method stub
		return false;
	}

}
